<?php
if(isset($_FILES["file"]["type"]))
{
require_once('ImageManipulator.php');
require_once ('swiftmail/lib/swift_required.php'); //sinon y a des erreurs parceque config contient une instruction swiftmail
require_once('config.inc.php');
if ($_FILES['file']['error'] > 0) {
					echo "Error: " . $_FILES['file']['error'] . "<br />";
				} else {
					// array of valid extensions
					$validExtensions = array('.jpg', '.jpeg', '.gif', '.png');
					// get extension of the uploaded file
					$fileExtension = strrchr($_FILES['file']['name'], ".");
					// check if file Extension is on the list of allowed ones
					if (in_array($fileExtension, $validExtensions)) {
						$newNamePrefix = time() . '_';
						$manipulator = new ImageManipulator($_FILES['file']['tmp_name']);
						$manipulator->save('../img/uploads/products/large/' . $newNamePrefix . $_FILES['file']['name']);
						$uploadFilename=$newNamePrefix . $_FILES['file']['name'];
					echo'<div class="animated fadeOut" style="-webkit-animation-duration: 3s;"><div class="alert alert-success">
      <strong>Well done!</strong> Image successfully uploaded
    </div></div>';
						
						
			$req = $db->prepare('INSERT INTO jktrade_img(img_rel, img_name)
													VALUES(:img_rel, :img_name)');
			$req->execute(array(
				'img_rel' => $_POST['pr_id'],
				'img_name' => $uploadFilename
				
			));
					} 
				}

}


		
?>